package cn.zhyjohn.paysystem.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * Setting Swagger Class
 * @author JOHN
 * @date 2019-4-16
 */
@EnableSwagger2
@Configuration
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    @Bean
    public Docket managerApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("支付系统")
                .apiInfo(apiInfo("支付系统接口文档"))
                .produces(Sets.newHashSet("application/json;charset=UTF-8"))
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.zhyjohn.paysystem.action"))
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo(String desc) {
        return new ApiInfoBuilder().title("支付系统接口文档")
                .description(desc)
                .version("1.0.0")
                .contact(new Contact("JOHN", "", ""))
                .build();
    }

    /**
     * add head param
     *
     * @return List<Parameter>
     */
    private List<Parameter> parameter() {
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = Lists.newArrayList();
        tokenPar
                .name("grant-token")
                .description("授权令牌")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false).build();

        pars.add(tokenPar.build());
        return pars;
    }
}